using System;
using System.Text;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Configuration;


namespace cmdPhone
{
    static class Program
    {
        [STAThread]
        static void Main(string[] args)
        {   
            InputReader input = new InputReader();

            //Run setup wizzard if required
            if (!hasSetupFinishedSuccessfully())
            {
                SetupWizzard.web21cSetupWizzard();
            }

            //If the application is started with parameters
            if (args.Length != 0)
            {
                input.readInput(args);
            }

            //Loop forever waiting for commands
            do
            {
               
                string[] commands = input.getCommands(Interaction.input());

                //Dealing with exit and quit commands
                if (commands.Length != 0)
                {
                    if (commands[0].Equals("exit") || commands[0].Equals("quit"))
                    {
                        break;
                    }
                }

                //InputReader will deal with differents provided commands/formats and call the relevant method 
                input.readInput(commands);
  
            } while (true);


            //Exit message
            Interaction.output(Resources.exit_application_message);
            
        }

        /// <summary>
        /// Asserts whether setup has finished successfully
        /// </summary>
        /// <returns>true if setup has finished, false otherwise</returns>
        private static bool hasSetupFinishedSuccessfully() 
        {
            Configuration appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (appConfig.AppSettings.Settings["setupFinished"].ToString().ToLower() == "true")
            {
                return true;
            }
            else 
            {
                return false;
            }
            
        }


    }
}